package com.xiyu.service.controller.admin.elder;
import com.xiyu.service.vo.elder.visit.VisitSingleGetOutput;
import com.xiyu.service.vo.elder.visit.VisitUpdateStatusInput;
import com.xiyu.service.vo.elder.visit.VisitUpdateInput;
import com.xiyu.service.vo.elder.visit.VisitCreateInput;
import com.xiyu.service.vo.elder.visit.VisitPageQueryOutput;
import com.xiyu.service.vo.elder.visit.VisitPageQueryInput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.framework.excel.core.util.ExcelUtils;

import com.xiyu.service.framework.operateLog.core.annotations.OperateLog;
import static com.xiyu.service.framework.operateLog.core.enums.OperateTypeEnum.*;

import com.xiyu.service.service.elder.VisitService;

@Tag(name = "来访登记")
@RestController
@RequestMapping("/elder/visit")
@Validated
public class VisitController {

    @Resource
    private VisitService visitService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询来访登记")
    @PreAuthorize("@ss.hasPermission('elder:visit:query')")
    public CommonResult<PageResult<VisitPageQueryOutput>> pageQuery(@Valid VisitPageQueryInput inputVO) {
        return success(visitService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新建来访登记")
    @PreAuthorize("@ss.hasPermission('elder:visit:create')")
    public CommonResult<Long> create(@Valid @RequestBody VisitCreateInput inputVO) {
        return success(visitService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新来访登记")
    @PreAuthorize("@ss.hasPermission('elder:visit:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody VisitUpdateInput inputVO) {
        return success(visitService.update(inputVO));
    }

    @PostMapping("/update-status")
    @Operation(summary = "更新来访登记状态")
    public CommonResult<Boolean> updateStatus(@Valid @RequestBody VisitUpdateStatusInput inputVO) {
        return success(visitService.updateStatus(inputVO));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个来访登记")
    @Parameter(name = "id", description = "来访登记主键ID", example = "")
    public CommonResult<VisitSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(visitService.singleGet(id));
    }

}
